#include "common.h"

Blok::Blok()
{
	fX = fY = fZ = 0.0f;
	iSize =	1;
	iAttachedTo = 0;

	this->createDisplayList();
}

void Blok::createDisplayList()
{
	this->displayList = glGenLists(1);

	glNewList(this->displayList, GL_COMPILE);
		this->draw();
	glEndList();	
}	
void Blok::render()
{
	glCallList(this->displayList);
}

void Blok::draw()
{
	// front
	glColor3f(0.0f, 1.0f, 0.0f); // green
	glVertex3f(fX - iSize, fY - iSize, fZ +	iSize); // bl
	glVertex3f(fX - iSize, fY + iSize, fZ +	iSize); // tl
	glVertex3f(fX + iSize, fY + iSize, fZ +	iSize); // tr
	glVertex3f(fX + iSize, fY - iSize, fZ + iSize); // br

	// top
	glColor3f(1.0f, 0.0f, 0.0f); // red
	glVertex3f(fX - iSize, fY + iSize, fZ + iSize);
	glVertex3f(fX - iSize, fY + iSize, fZ - iSize);
	glVertex3f(fX + iSize, fY + iSize, fZ - iSize);
	glVertex3f(fX + iSize, fY + iSize, fZ + iSize);

	// right
	glColor3f(0.0f, 0.0f, 1.0f); // blue
	glVertex3f(fX + iSize, fY + iSize, fZ + iSize);
	glVertex3f(fX + iSize, fY + iSize, fZ - iSize);
	glVertex3f(fX + iSize, fY - iSize, fZ - iSize);
	glVertex3f(fX + iSize, fY - iSize, fZ + iSize);

	// left
	glColor3f( 1.0f, 1.0f, 0.0f);
	glVertex3f(fX - iSize, fY + iSize, fZ + iSize);
	glVertex3f(fX - iSize, fY + iSize, fZ - iSize);
	glVertex3f(fX - iSize, fY - iSize, fZ - iSize);
	glVertex3f(fX - iSize, fY - iSize, fZ + iSize);

	// bottom
	glColor3f( 1.0f, 1.0f, 1.0f); // OK
	glVertex3f(fX - iSize, fY - iSize, fZ +	iSize);
	glVertex3f(fX - iSize, fY - iSize, fZ - iSize);
	glVertex3f(fX + iSize, fY - iSize, fZ - iSize);
	glVertex3f(fX + iSize, fY - iSize, fZ + iSize);

	// back
	glColor3f( 1.0f, 1.0f, 1.0f); // pink
	glVertex3f(fX - iSize, fY - iSize, fZ -	iSize); 
	glVertex3f(fX - iSize, fY + iSize, fZ -	iSize); 
	glVertex3f(fX + iSize, fY + iSize, fZ -	iSize); 
	glVertex3f(fX + iSize, fY - iSize, fZ - iSize); 


}